package com.scpii.api.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.scpii.api.common.Constants;

public class DateUtil {
	private static final Logger logger = Logger.getLogger(DateUtil.class);

	private static final DateFormat DATE_FORMAT = new SimpleDateFormat(
			Constants.RFC3339_FORMAT);

	public static Date parseDate(String date) {
		if (StringUtils.isBlank(date)) {
			return null;
		}
		try {
			return DATE_FORMAT.parse(date);
		} catch (ParseException e) {
			if (logger.isDebugEnabled()) {
				logger.debug("could't parse date " + date
						+ " with dateformatter " + Constants.RFC3339_FORMAT, e);
			}
			return null;
		}
	}
}
